<HTML>
<HEAD>
<TITLE>All Graphs</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
</HEAD>
<BODY>
<?php

if (isset($_GET['sub'])) $sub = $_GET['sub'];
else $sub = "apw";
if (isset($_GET['sort'])) $sort = $_GET['sort'];
else $sort = "name";
if (	($sort === "agrowth" || $sort === "pgrowth" || $sort === "filltime" || $sort === "secondlastfilltime") &&
	isset($_GET['t']) && is_numeric($_GET['t']) &&
	($_GET['t'] == 2 || $_GET['t'] == 14 || $_GET['t'] == 56 || $_GET['t'] == 112 || $_GET['t'] == 224 || $_GET['t'] == 336))
		$t = $_GET['t'];
else $t = 112;

if (isset($_GET['size']) && is_numeric($_GET['size'])) {
	$size = $_GET['size'];
} else {
	$size = 0;
}


$options = array(
	'sub' => array(
		'all' => "All graphs (Slow!)",
		'apw' => "Active + Waiting",
		'wl' => "Waiting lists",
		'wt' => "Waiting times",
		'tr' => "Training types"
	),
	'sort' => array(
		'name' => "English name",
		'lname' => "Local name",
		'active' => "Active users",
		'waiting' =>"Waiting users",
		'total' => "Total users",
		'id' => "LeagueID (Age)",
		'agrowth' => "Absolute growth...",
		'pgrowth' => "Percentual growth...",
		'filltime' => "Est. fill time, extrapolating...",
		'secondlastfilltime' => "Est. fill time 2nd-bottom div, extrap...",
	),
	't' => array(
		'2' => "2 days ago",
		'14' => "2 weeks ago",
		'56' => "8 weeks ago",
		'112' => "A season ago",
		'224' => "2 seasons ago",
		'336' => "3 seasons ago"
	),
	'size' => array(
		'0' => "Normal",
		'1' => "HUGE!"
	)
);

?>
<form name="sel" method="get" action="<?php echo $_SERVER["REQUEST_URI"] ?>">
Show <select name="sub" onchange="sel.submit()">
<?php //subselect dropdown
	
foreach (array_keys($options['sub']) as $name) {
        echo "<option value=\"$name\"";
        if ($name === $sub) echo " selected=\"selected\"";
        echo ">{$options['sub'][$name]}</option>\n";
}

?>
</select>
 ordered by 
<select name="sort" onchange="sel.submit()">
<?php //sort dropdown

foreach (array_keys($options['sort']) as $name) {
	echo "<option value=\"$name\"";
	if ($name === $sort) echo " selected=\"selected\"";
	echo ">{$options['sort'][$name]}</option>\n";
}

?>
</select>
<?php //timespan dropdown
if ($sort === "agrowth" || $sort === "pgrowth" || $sort === "filltime" || $sort === "secondlastfilltime") {
?>
 from  
<select name="t" onchange="sel.submit()">
<?php
	foreach (array_keys($options['t']) as $name) {
		echo "<option value=\"$name\"";
		if ($name == $t) echo " selected=\"selected\"";
		echo ">{$options['t'][$name]}</option>\n";
	}
?>
</select>
<?php
}
?>

<?php //size dropdown
if ($sub === "apw" || $sub === "wl" || $sub === "tr" || $sub === "wt") {
?>
graph size: <select name="size" onchange="sel.submit()">
<?php
	foreach (array_keys($options['size']) as $name) {
		echo "<option value=\"$name\"";
		if ($name == $size) echo " selected=\"selected\"";
		echo ">{$options['size'][$name]}</option>\n";
	}
?>
</select>
<?php
}
?>
<input type="submit" value="Go!">
</form>
<?php

ini_set("memory_limit","20M");
require_once("track.inc.php");
require_once("database.inc.php");

hit();

$dbh = connect_db();

$where = "";

if ($sort === "active") {
	$sortby = "ActiveUsers DESC, EnglishName";
} else if ($sort === "waiting") {
	$sortby = "WaitingUsers DESC, ActiveUsers DESC, EnglishName";
} else if ($sort === "total") {
	$sortby = "(Activeusers + WaitingUsers) DESC, EnglishName";
} else if ($sort === "id") {
	$sortby = "leagues_daily.LeagueID ASC";
} else if ($sort === "agrowth") {
	$sortby = "d$t DESC, p$t DESC";
} else if ($sort === "pgrowth") {
	$sortby = "p$t DESC, d$t DESC";
} else if ($sort === "filltime") {
	$sortby = "daystofill";
	$where = "AND activeusers+waitingusers <= newcumsize AND ((newcumsize - (activeusers+waitingusers))/((activeusers+waitingusers) - (Active$t+Waiting$t)))*$t > 0";
} else if ($sort === "secondlastfilltime") {
	$sortby = "daystofill";
	$where = "+1 AND activeusers+waitingusers <= newcumsize AND ((newcumsize - (activeusers+waitingusers))/((activeusers+waitingusers) - (Active$t+Waiting$t)))*$t > 0";
} else if ($sort === "lname") {
	$sortby = "LeagueName";
} else {
	$sortby = "EnglishName";
}

$sizeword = "";
if ($size > 0) $sizeword = "big";

if (!$leagues = mysql_query("SELECT leagues_daily.leagueid, englishname, leaguename, history_n.*, divsizes.*, 
((newcumsize - (activeusers+waitingusers))/((activeusers+waitingusers) - (Active$t+Waiting$t)))*$t daystofill, 
CAST(activeusers-active2 AS SIGNED) d2, round((CAST(activeusers-active2 AS SIGNED) / active2)*100,2) p2, 
CAST(activeusers-active14 AS SIGNED) d14, round((CAST(activeusers-active14 AS SIGNED) / active14)*100,2) p14, 
CAST(activeusers-active56 AS SIGNED) d56, round((CAST(activeusers-active56 AS SIGNED) / active56)*100,2) p56, 
CAST(activeusers-active112 AS SIGNED) d112, round((CAST(activeusers-active112 AS SIGNED) / active112)*100,2) p112, 
CAST(activeusers-active224 AS SIGNED) d224, round((CAST(activeusers-active224 AS SIGNED) / active224)*100,2) p224,
CAST(activeusers-active336 AS SIGNED) d336, round((CAST(activeusers-active336 AS SIGNED) / active336)*100,2) p336 
FROM leagues_daily, history_n, divsizes 
WHERE leagues_daily.leagueid != 255 AND leagues_daily.leagueid = history_n.leagueid AND leagues_daily.numberoflevels = divsizes.level $where 
ORDER BY $sortby", $dbh)) die(mysql_error());
?>
<a href="maptrick.php">Click here</a> to return to Maptrick; click a graph below to look that country up on the Maptrick page.<br /><br />
<a href="maptrick.php"><img border="0" src="graphs/<?php echo $sizeword; ?>global.png" /><img border="0" src="graphs/<?php echo $sizeword; ?>global-w.png"></a>
<a href="training.php"><img border="0" src="graphs/<?php echo $sizeword; ?>tglobal.png"></a><br /><br />
<?php
if ($sort === "filltime") echo "Please note that countries that are currently shrinking, or already filled, are not included in this list.<br /><br />\n";
if ($sort === "secondlastfilltime") echo "Please note that countries that are currently shrinking, or already need their bottom division, are not included in this list.<br /><br />\n";

while ($league = mysql_fetch_array($leagues)) {
	$id = $league['leagueid'];
	echo "{$league['englishname']} / {$league['leaguename']}";
	if ($sort === "filltime") echo ": " . round($league['daystofill'],0) . " days to fill (" . round($league['daystofill']/112,2) . " seasons)";
	if ($sort === "secondlastfilltime") echo ": " . round($league['daystofill'],0) . " days to fill second-lowest division (" . round($league['daystofill']/112,2) . " seasons)";
	echo "<br />\n";
	echo "<a href=\"maptrick.php?leagueid=$id\">";
	if ($sub === "all" || $sub === "apw") echo "<IMG BORDER=\"0\" SRC=\"graphs/$sizeword$id.png\"/>";
	if ($sub === "all" || $sub === "wl") echo "<IMG BORDER=\"0\" SRC=\"graphs/$sizeword$id-w.png\">";
	if ($sub === "all" || $sub === "wt") echo "<IMG BORDER=\"0\" SRC=\"graphs/$sizeword$id-t.png\">";
	echo "</a>";
	if ($sub === "all" || $sub === "tr") echo "<a href=\"training.php\"><IMG BORDER=\"0\" SRC=\"graphs/{$sizeword}t$id.png\"></a>\n";
	echo "<br />";
}
?>
A table with data from the period December 2003 - January 2005 can be found at <A HREF="http://www.dandy.at/managers.html">http://www.dandy.at/managers.html</A>.
<?php urchin(); ?>
</BODY>
</HTML>
